package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.OlivePlantCateMapper;
import com.ruoyi.system.domain.OlivePlantCate;
import com.ruoyi.system.service.IOlivePlantCateService;

/**
 * 存放种植区的种类Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-30
 */
@Service
public class OlivePlantCateServiceImpl implements IOlivePlantCateService 
{
    @Autowired
    private OlivePlantCateMapper olivePlantCateMapper;

    /**
     * 查询存放种植区的种类
     * 
     * @param cateId 存放种植区的种类主键
     * @return 存放种植区的种类
     */
    @Override
    public OlivePlantCate selectOlivePlantCateByCateId(Long cateId)
    {
        return olivePlantCateMapper.selectOlivePlantCateByCateId(cateId);
    }

    /**
     * 查询存放种植区的种类列表
     * 
     * @param olivePlantCate 存放种植区的种类
     * @return 存放种植区的种类
     */
    @Override
    public List<OlivePlantCate> selectOlivePlantCateList(OlivePlantCate olivePlantCate)
    {
        return olivePlantCateMapper.selectOlivePlantCateList(olivePlantCate);
    }

    /**
     * 新增存放种植区的种类
     * 
     * @param olivePlantCate 存放种植区的种类
     * @return 结果
     */
    @Override
    public int insertOlivePlantCate(OlivePlantCate olivePlantCate)
    {
        return olivePlantCateMapper.insertOlivePlantCate(olivePlantCate);
    }

    /**
     * 修改存放种植区的种类
     * 
     * @param olivePlantCate 存放种植区的种类
     * @return 结果
     */
    @Override
    public int updateOlivePlantCate(OlivePlantCate olivePlantCate)
    {
        olivePlantCate.setUpdateTime(DateUtils.getNowDate());
        return olivePlantCateMapper.updateOlivePlantCate(olivePlantCate);
    }

    /**
     * 批量删除存放种植区的种类
     * 
     * @param cateIds 需要删除的存放种植区的种类主键
     * @return 结果
     */
    @Override
    public int deleteOlivePlantCateByCateIds(Long[] cateIds)
    {
        return olivePlantCateMapper.deleteOlivePlantCateByCateIds(cateIds);
    }

    /**
     * 删除存放种植区的种类信息
     * 
     * @param cateId 存放种植区的种类主键
     * @return 结果
     */
    @Override
    public int deleteOlivePlantCateByCateId(Long cateId)
    {
        return olivePlantCateMapper.deleteOlivePlantCateByCateId(cateId);
    }


    /**
     * 校验种植区分类名称
     * @param olivePlantCate
     * @return
     */
    public boolean checkOlivePlantNameUnique(OlivePlantCate olivePlantCate){
        String cate_name = StringUtils.isNull(olivePlantCate.getCateName())?"-1":olivePlantCate.getCateName();
        OlivePlantCate cate = olivePlantCateMapper.checkOliveCateNameUnique(cate_name);
        if(StringUtils.isNotNull(cate) && cate.getCateName().equals(cate_name)){
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;

    }

}
